action (parameter type)

Action parameters are specified with type="action" in the parameter definition.

This is an example definition of an action parameter:

    {name="MyAction", type="action", action=myActionFunction}

The action calls the lua function specified with action. The function should be implemented above the call to Tool.register. The first argument to the function is self, the instance of the custom tool class.

local function myActionFunction(self)
  local result = self.parameters.MyInt1 + self.parameters.MyInt2
  print("Sum: " .. result)
end

The UI control is a button. The button label is customized by mapping the parameter name in the language resource files.

../../../_images/ui-action-button.png

An action button

Action definition table keys

name:

The name of the action.

type:

Should always be "action".

action:

A reference to a lua function that will be called by the action.

ui:

Can be set to false to hide the button, so that the action can only be called from the command channel.

Action arguments

It is possible to specify arguments to an action:

    {name="MyActionWithArgs", type="action", action=myFunctionWithArguments, ui=false, args={
      {name="arg1", type="number"},
      {name="arg2", type="number"}
    }}

They will be received as additional arguments to the lua function implementation.

local function myFunctionWithArguments(self, arg1, arg2)
  local result = self.parameters.MyInt1 + arg1 + arg2
  print("Sum: " .. result)
end

Action argument definition table keys

name:

The name of the argument.

type:

Supported argument types are "bool", "number", and "string".

Note

Arguments can only be used when calling an action from the Command channel, they will not be set when calling an action from a button in the user interface. It is recommended to set ui=false for actions with arguments.